home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / smaltalk / gnu_st.lha / gnu_st / smalltalk-1.1.1 / Association.st < prev    next >
Text File  |  1991-09-12  |  3KB  |  114 lines

  1. "======================================================================
  2. |
  3. |   Association Method Definitions
  4. |
  5.  ======================================================================"
  6.  
  7.  
  8. "======================================================================
  9. |
  10. | Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  11. | Written by Steve Byrne.
  12. |
  13. | This file is part of GNU Smalltalk.
  14. |
  15. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  16. | under the terms of the GNU General Public License as published by the Free
  17. | Software Foundation; either version 1, or (at your option) any later version.
  18. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  19. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  20. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  21. | details.
  22. | You should have received a copy of the GNU General Public License along with
  23. | GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  24. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  25. |
  26.  ======================================================================"
  27.  
  28.  
  29. "
  30. |     Change Log
  31. | ============================================================================
  32. | Author       Date       Change 
  33. | sbyrne     25 Apr 89      created.
  34. |
  35. "
  36.  
  37. LookupKey subclass: #Association
  38.       instanceVariableNames: 'key value'
  39.       classVariableNames: ''
  40.       poolDictionaries: ''
  41.       category: nil.
  42.  
  43. Association comment: 
  44. 'My instances represent a mapping between two objects.  Typically, my
  45. "key" object is a symbol, but I don''t require this.  My "value" object has 
  46. no conventions associated with it; it can be any object at all.' !
  47.           
  48.  
  49. !Association class methodsFor: 'basic'!
  50.  
  51. key: aKey value: aValue
  52.     ^self new key: aKey value: aValue
  53. !!
  54.  
  55.  
  56.  
  57. !Association methodsFor: 'accessing'!
  58.  
  59. value: aValue
  60.     value _ aValue
  61. !
  62.  
  63. key: aKey value: aValue
  64.     key _ aKey.
  65.     value _ aValue
  66. !
  67.  
  68. key
  69.     ^key
  70. !
  71.  
  72. value
  73.     ^value
  74. !!
  75.  
  76.  
  77.  
  78. !Association methodsFor: 'testing'!
  79.  
  80. = anAssociation
  81.     ^key = anAssociation key and: [ value = anAssociation value ]
  82. !
  83.  
  84. hash
  85.     ^key hash + value hash
  86.  
  87. !!
  88.  
  89.  
  90.  
  91.  
  92. !Association methodsFor: 'printing'!
  93.  
  94. printOn: aStream
  95.     self key storeOn: aStream.
  96.     aStream nextPutAll: ' -> '.
  97.     self value storeOn: aStream
  98. !!
  99.  
  100.  
  101.  
  102. !Association methodsFor: 'storing'!
  103.  
  104. storeOn: aStream
  105.     aStream nextPutAll: '(Association key: '.
  106.     self key storeOn: aStream.
  107.     aStream nextPutAll: ' value: '.
  108.     self value storeOn: aStream.
  109.     aStream nextPut: $)
  110. !!
  111.  
  112.